/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package restauranteaplicacion.Ingresos;

import Clases.Observador;
import java.awt.Component;
import java.util.Observable;
import java.util.Observer;
import restauranteaplicacion.MDI;
import CapaNegocios.CNPuestos;
import entidad.Puestos;
import Clases.ComboBox;
import java.util.List;
import entidad.Empleados;
import CapaNegocios.CNEmpleados;
import java.awt.Color;
import javax.swing.JOptionPane;
import java.util.Calendar;


/**
 *
 * @author victor
 */
public class IngresoEmpleado extends javax.swing.JInternalFrame implements Observer {

    /**
     * Creates new form IngresoEmpleado
     */
    Observador obs;
    Observador padre;
    
    public IngresoEmpleado() {
        initComponents();
        obs=new Observador();
        obs.addObserver(this);
        cargarPuesto();
        empleados1 = null;
    }
    
    public IngresoEmpleado(Observador obs1 ) {
        initComponents();
        obs=obs1;
        cargarPuesto();
        empleados1 = null;
        dateEntrada.setDate(Calendar.getInstance().getTime());
    }
    
    public IngresoEmpleado(Observador obs1,Empleados empleado ) {
        initComponents();
        obs=obs1;
        cargarPuesto();
        ingresarNuevoProveedor(empleado, empleados1);
        dateNac.setDate(empleados1.getFechaNac());
        if(empleados1.getSexo().equals("M"))
            cbSexo.setSelectedItem("MASCULINO");
        else
            cbSexo.setSelectedItem("FEMENINO");
        dateEntrada.setDate(empleados1.getFechaEntrada());
        cbPuesto.setSelectedItem(new ComboBox(empleados1.getPuestoidPuesto().getIdPuestos(),
                empleados1.getPuestoidPuesto().getNombrePuesto()));
        cbDescanso.setSelectedItem(empleados1.getDiaDescanso());
    }
    
    private void ingresarNuevoProveedor(Empleados viejoPro, Empleados empldeadoNuevo )
    {
        empldeadoNuevo.setNombre(viejoPro.getNombre());
        empldeadoNuevo.setActivo(viejoPro.getActivo());
        empldeadoNuevo.setCorreo(viejoPro.getCorreo());
        empldeadoNuevo.setTelefono(viejoPro.getTelefono());
        empldeadoNuevo.setApellido(viejoPro.getApellido());
        empldeadoNuevo.setCarneIggs(viejoPro.getCarneIggs());
        empldeadoNuevo.setCelular(viejoPro.getCelular());
        empldeadoNuevo.setDiaDescanso(viejoPro.getDiaDescanso());
        empldeadoNuevo.setDireccionImagen(viejoPro.getDireccionImagen());
        empldeadoNuevo.setDpi(viejoPro.getDpi());
        empldeadoNuevo.setFechaEntrada(viejoPro.getFechaEntrada());
        empldeadoNuevo.setFechaNac(viejoPro.getFechaNac());
        empldeadoNuevo.setFechaSalida(viejoPro.getFechaSalida());
        empldeadoNuevo.setHorario(viejoPro.getHorario());
        empldeadoNuevo.setIdEmpleados(viejoPro.getIdEmpleados());
        empldeadoNuevo.setPagossueldosCollection(viejoPro.getPagossueldosCollection());
        empldeadoNuevo.setProfesion(viejoPro.getProfesion());
        empldeadoNuevo.setPuestoidPuesto(viejoPro.getPuestoidPuesto());
        empldeadoNuevo.setSexo(viejoPro.getSexo());
        empldeadoNuevo.setSucursalidSucursal(viejoPro.getSucursalidSucursal());
        empldeadoNuevo.setSueldo(viejoPro.getSueldo());
        empldeadoNuevo.setUsuariosCollection(viejoPro.getUsuariosCollection());
        
    }
    
    private void cargarPuesto()
    {
        cbPuesto.removeAllItems();
        List<Puestos> lista = CNPuestos.buscarTodos();
        for(Puestos puesto : lista)
            cbPuesto.addItem(new ComboBox(puesto.getIdPuestos(), puesto.getNombrePuesto()));
    }


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        empleados1 = new entidad.Empleados();
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtApellido = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtDPI = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        btnCancelar = new javax.swing.JButton();
        jLabel18 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        dateNac = new com.toedter.calendar.JDateChooser();
        jLabel9 = new javax.swing.JLabel();
        cbSexo = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        txtProfesion = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtTel = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        txtCelular = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        txtSueldo = new javax.swing.JTextField();
        txtIggs = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        dateEntrada = new com.toedter.calendar.JDateChooser();
        jLabel19 = new javax.swing.JLabel();
        cbPuesto = new javax.swing.JComboBox();
        btnGuardar = new javax.swing.JButton();
        btnPuesto = new javax.swing.JButton();
        jLabel16 = new javax.swing.JLabel();
        cbDescanso = new javax.swing.JComboBox();
        jLabel17 = new javax.swing.JLabel();
        txtCorreo = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        txtHorario = new javax.swing.JTextField();

        setBackground(new java.awt.Color(255, 255, 255));
        setClosable(true);
        setIconifiable(true);
        setTitle("Ingreso de Empleados");
        setAutoscrolls(true);
        setMaximumSize(new java.awt.Dimension(1000, 540));
        setMinimumSize(new java.awt.Dimension(1000, 520));
        setPreferredSize(new java.awt.Dimension(1000, 510));
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.PAGE_AXIS));

        jPanel1.setBackground(new java.awt.Color(54, 149, 240));
        jPanel1.setMaximumSize(new java.awt.Dimension(988, 50));
        jPanel1.setMinimumSize(new java.awt.Dimension(246, 50));
        jPanel1.setPreferredSize(new java.awt.Dimension(988, 50));

        jLabel4.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Empleados");
        jPanel1.add(jLabel4);

        getContentPane().add(jPanel1);

        jPanel4.setPreferredSize(new java.awt.Dimension(988, 430));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setPreferredSize(new java.awt.Dimension(494, 500));

        jLabel1.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel1.setText("Nombre");

        txtNombre.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtNombre.setNextFocusableComponent(txtApellido);

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, empleados1, org.jdesktop.beansbinding.ELProperty.create("${nombre}"), txtNombre, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtNombre.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtNombreFocusGained(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel2.setText("Apellido");

        txtApellido.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtApellido.setNextFocusableComponent(txtDPI);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, empleados1, org.jdesktop.beansbinding.ELProperty.create("${apellido}"), txtApellido, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtApellido.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtApellidoFocusGained(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel5.setText("No. DPI");

        txtDPI.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtDPI.setNextFocusableComponent(dateNac);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, empleados1, org.jdesktop.beansbinding.ELProperty.create("${dpi}"), txtDPI, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtDPI.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtDPIFocusGained(evt);
            }
        });

        jLabel14.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N

        btnCancelar.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/restauranteaplicacion/Ingresos/circle-x-3x.png"))); // NOI18N
        btnCancelar.setText("Salir");
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        jLabel18.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel18.setText("INFORMACION GENERAL");

        jLabel7.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel7.setText("Fecha de Nacimiento");

        dateNac.setNextFocusableComponent(cbSexo);

        jLabel9.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel9.setText("Sexo");

        cbSexo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MASCULINO", "FEMENINO" }));
        cbSexo.setNextFocusableComponent(txtProfesion);

        jLabel10.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel10.setText("Profesión");

        txtProfesion.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtProfesion.setNextFocusableComponent(txtTel);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, empleados1, org.jdesktop.beansbinding.ELProperty.create("${profesion}"), txtProfesion, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jLabel8.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel8.setText("Telefono");

        txtTel.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtTel.setNextFocusableComponent(txtCelular);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, empleados1, org.jdesktop.beansbinding.ELProperty.create("${telefono}"), txtTel, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtTel.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTelKeyTyped(evt);
            }
        });

        jLabel15.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel15.setText("Cel.");

        txtCelular.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtCelular.setNextFocusableComponent(dateEntrada);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, empleados1, org.jdesktop.beansbinding.ELProperty.create("${celular}"), txtCelular, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtCelular.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtCelularFocusGained(evt);
            }
        });
        txtCelular.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCelularKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(96, 96, 96)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(99, 99, 99)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtDPI, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(11, 11, 11)
                                .addComponent(jLabel18))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel9)
                            .addComponent(jLabel10)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(dateNac, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(txtProfesion, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                            .addComponent(txtTel, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(jLabel15)))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(txtCelular)))
                            .addComponent(cbSexo, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(29, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel14)
                    .addGap(484, 484, Short.MAX_VALUE)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel18)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtDPI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(dateNac, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cbSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtProfesion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel10)))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15)
                    .addComponent(txtCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addComponent(btnCancelar)
                .addGap(26, 26, 26))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                    .addContainerGap(478, Short.MAX_VALUE)
                    .addComponent(jLabel14)
                    .addContainerGap()))
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setPreferredSize(new java.awt.Dimension(494, 500));

        txtSueldo.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtSueldo.setNextFocusableComponent(cbPuesto);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, empleados1, org.jdesktop.beansbinding.ELProperty.create("${sueldo}"), txtSueldo, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtSueldo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtSueldoFocusGained(evt);
            }
        });
        txtSueldo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtSueldoKeyTyped(evt);
            }
        });

        txtIggs.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtIggs.setNextFocusableComponent(txtSueldo);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, empleados1, org.jdesktop.beansbinding.ELProperty.create("${carneIggs}"), txtIggs, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jLabel13.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel13.setText("Puesto");

        jLabel12.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel12.setText("Sueldo");

        jLabel11.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel11.setText("Carne Del IGGS");

        jLabel6.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel6.setText("Fecha de entrada");

        dateEntrada.setNextFocusableComponent(txtIggs);

        jLabel19.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel19.setText("INFORMACION LABORAL");

        cbPuesto.setNextFocusableComponent(cbDescanso);

        btnGuardar.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/circle-check-3x.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnGuardar.setNextFocusableComponent(btnCancelar);
        btnGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnPuesto.setBackground(new java.awt.Color(255, 255, 255));
        btnPuesto.setForeground(new java.awt.Color(102, 102, 255));
        btnPuesto.setText("+");
        btnPuesto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPuestoActionPerformed(evt);
            }
        });

        jLabel16.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel16.setText("Dia descanso");

        cbDescanso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado", "Domingo" }));
        cbDescanso.setNextFocusableComponent(txtCorreo);

        jLabel17.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel17.setText("Correo");

        txtCorreo.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtCorreo.setNextFocusableComponent(txtHorario);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, empleados1, org.jdesktop.beansbinding.ELProperty.create("${correo}"), txtCorreo, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtCorreo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCorreoKeyTyped(evt);
            }
        });

        jLabel20.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel20.setText("Horario");

        txtHorario.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtHorario.setNextFocusableComponent(btnGuardar);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, empleados1, org.jdesktop.beansbinding.ELProperty.create("${horario}"), txtHorario, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtHorario.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtHorarioKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12))
                .addGap(76, 76, 76)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbDescanso, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(txtSueldo, javax.swing.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addComponent(cbPuesto, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(btnPuesto))
                        .addComponent(txtIggs))
                    .addComponent(dateEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCorreo, javax.swing.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE))
                .addGap(21, 21, 21))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(156, 156, 156)
                        .addComponent(jLabel19))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel17)
                            .addComponent(jLabel6)
                            .addComponent(jLabel16)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel20)
                        .addGap(132, 132, 132)
                        .addComponent(txtHorario)))
                .addGap(21, 21, 21))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(185, 185, 185))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel19)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(dateEntrada, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtIggs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtSueldo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addGap(13, 13, 13)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbPuesto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(btnPuesto))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(cbDescanso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(txtCorreo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(txtHorario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(53, 53, 53)
                .addComponent(btnGuardar)
                .addGap(25, 25, 25))
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 428, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 428, Short.MAX_VALUE)
                .addContainerGap())
        );

        getContentPane().add(jPanel4);

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private boolean validar()
    {
        boolean val=true;
        if(txtNombre.getText().equals(""))
        {
            val=false;
            txtNombre.setBackground(Color.getHSBColor(255, 204, 204));
        }
        if(txtApellido.getText().equals(""))
        {
            val=false;
            txtApellido.setBackground(Color.getHSBColor(255, 204, 204));
        }
        if(txtCelular.getText().equals(""))
        {
            val=false;
            txtCelular.setBackground(Color.getHSBColor(255, 204, 204));
        }
        if(txtDPI.getText().equals(""))
        {
            val=false;
            txtDPI.setBackground(Color.getHSBColor(255, 204, 204));
        }
        return val;
    }
    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // TODO add your handling code here:
        if(validar())
        {
            if(empleados1!=null)
            {
                empleados1.setPuestoidPuesto(CNPuestos.buscarId(((ComboBox)cbPuesto.getSelectedItem()).getId()));
                empleados1.setFechaEntrada(dateEntrada.getDate());
                empleados1.setFechaNac(dateNac.getDate());
                if(cbSexo.getSelectedItem().toString().equals("MASCULINO"))
                    empleados1.setSexo("M");
                else
                    empleados1.setSexo("F");
                empleados1.setDiaDescanso(cbDescanso.getSelectedItem().toString());
                if(CNEmpleados.modificar(empleados1))
                {
                    JOptionPane.showMessageDialog(this, "Se ha modificado correctamente", 
                                "Informacion", JOptionPane.INFORMATION_MESSAGE);
                    obs.actualizar();
                    this.setVisible(false);
                }
                else
                {
                    JOptionPane.showMessageDialog(this, "No se ha Modifico correctamente", 
                            "Informacion", JOptionPane.ERROR_MESSAGE);
                    return;
                }                  
            }
            else
            {
                Empleados emp = new Empleados();
                emp.setNombre(txtNombre.getText());
                emp.setApellido(txtApellido.getText());
                emp.setCarneIggs(txtIggs.getText());
                emp.setCelular(txtCelular.getText());
                emp.setCorreo(txtCorreo.getText());
                emp.setDiaDescanso(cbDescanso.getSelectedItem().toString());
                emp.setDpi(txtDPI.getText());
                emp.setFechaEntrada(dateEntrada.getDate());
                emp.setFechaNac(dateNac.getDate());
                emp.setHorario(txtHorario.getText());
                emp.setProfesion(txtProfesion.getText());
                emp.setPuestoidPuesto(CNPuestos.buscarId(((ComboBox)cbPuesto.getSelectedItem()).getId()));
                if(cbSexo.getSelectedItem().toString().equals("MASCULINO"))
                    emp.setSexo("M");
                else
                    emp.setSexo("F");
                emp.setSueldo(Float.parseFloat(txtSueldo.getText()));
                emp.setTelefono(txtTel.getText());
                emp.setActivo(true);
                emp.setDireccionImagen("");
                if(CNEmpleados.insertar(emp))
                {
                    JOptionPane.showMessageDialog(this, "Se ha guardado correctamente", 
                            "Informacion", JOptionPane.INFORMATION_MESSAGE);
                    limpiar();   
                    if(obs!=null)
                    {
                        obs.actualizar();
                        this.setVisible(false);
                    }
                }
                else
                    JOptionPane.showMessageDialog(this, "No se ha guardado correctamente", 
                            "Informacion", JOptionPane.ERROR_MESSAGE);
            }
        }    
        else
            JOptionPane.showMessageDialog(this, "No a ingresado correctamente la informacion", 
                    "Informacion", JOptionPane.ERROR_MESSAGE);
    }//GEN-LAST:event_btnGuardarActionPerformed

    public void limpiar()
    {
        txtNombre.setText("");
        txtApellido.setText("");
        txtCelular.setText("");
        txtCorreo.setText("");
        txtDPI.setText("");
        txtHorario.setText("");
        txtIggs.setText("");
        txtProfesion.setText("");
        txtSueldo.setText("");
        txtTel.setText("");
        txtNombre.requestFocus(true);
        
    }
    
    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        
        if(obs!=null)
            obs.actualizar();
        this.setVisible(false);
        // TODO add your handling code here:
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnPuestoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPuestoActionPerformed
        //TODO add your handling code here:
        padre = new  Observador();        
        IngresoPuesto ing = new IngresoPuesto(padre);
        //ing.show();
        MDI.getDesktopPane().add(ing);   
        padre.addObserver(this);
        this.desactivar();  
        ing.show();
        

    }//GEN-LAST:event_btnPuestoActionPerformed

    private void txtSueldoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSueldoKeyTyped
        // TODO add your handling code here:
        char c=evt.getKeyChar();  
        if((!Character.isDigit(c))&&(c != '.')) { 
              getToolkit().beep();                
              evt.consume(); 
          }
    }//GEN-LAST:event_txtSueldoKeyTyped

    private void txtCorreoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCorreoKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCorreoKeyTyped

    private void txtTelKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTelKeyTyped
        // TODO add your handling code here:
        char c=evt.getKeyChar();  
        if(!Character.isDigit(c)) { 
              getToolkit().beep();                
              evt.consume(); 
          }
    }//GEN-LAST:event_txtTelKeyTyped

    private void txtCelularKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCelularKeyTyped
        // TODO add your handling code here:
        char c=evt.getKeyChar();  
        if(!Character.isDigit(c)) { 
              getToolkit().beep();                
              evt.consume(); 
          }
    }//GEN-LAST:event_txtCelularKeyTyped

    private void txtHorarioKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtHorarioKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_txtHorarioKeyTyped

    private void txtNombreFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtNombreFocusGained
        // TODO add your handling code here:
        txtNombre.setBackground(Color.WHITE);
    }//GEN-LAST:event_txtNombreFocusGained

    private void txtApellidoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtApellidoFocusGained
        // TODO add your handling code here:
        txtApellido.setBackground(Color.WHITE);
    }//GEN-LAST:event_txtApellidoFocusGained

    private void txtDPIFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDPIFocusGained
        // TODO add your handling code here:
        txtDPI.setBackground(Color.WHITE);
    }//GEN-LAST:event_txtDPIFocusGained

    private void txtCelularFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCelularFocusGained
        // TODO add your handling code here:
        txtCelular.setBackground(Color.WHITE);
    }//GEN-LAST:event_txtCelularFocusGained

    private void txtSueldoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtSueldoFocusGained
        // TODO add your handling code here:
        Object o = evt.getSource(); 
        if(o instanceof javax.swing.JTextField)
        { 
            javax.swing.JTextField txt = (javax.swing.JTextField) o; 
            txt.setSelectionStart(0); 
            txt.setSelectionEnd(txt.getText().length()); 
        }
    }//GEN-LAST:event_txtSueldoFocusGained

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
        // TODO add your handling code here:
        if(obs!=null)
            obs.actualizar();
    }//GEN-LAST:event_formInternalFrameClosing

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnPuesto;
    private javax.swing.JComboBox cbDescanso;
    private javax.swing.JComboBox cbPuesto;
    private javax.swing.JComboBox cbSexo;
    private com.toedter.calendar.JDateChooser dateEntrada;
    private com.toedter.calendar.JDateChooser dateNac;
    private entidad.Empleados empleados1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JTextField txtApellido;
    private javax.swing.JTextField txtCelular;
    private javax.swing.JTextField txtCorreo;
    private javax.swing.JTextField txtDPI;
    private javax.swing.JTextField txtHorario;
    private javax.swing.JTextField txtIggs;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtProfesion;
    private javax.swing.JTextField txtSueldo;
    private javax.swing.JTextField txtTel;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    private void activar()
    {
        for(Component x :this.jPanel2.getComponents())
        {
            x.setEnabled(true);
        }
        for(Component x :this.jPanel3.getComponents())
        {
            x.setEnabled(true);
        }
        
    }
    
    private void desactivar()
    {
        for(Component x :this.jPanel2.getComponents())
        {
            x.setEnabled(false);
        }
        for(Component x :this.jPanel3.getComponents())
        {
            x.setEnabled(false);
        }
        
    }
    @Override
    public void update(Observable o, Object arg) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        activar();
        cargarPuesto();
    }
}
